package cn.ex.de001.common.utils;

import cn.ex.de001.common.enums.RETURN_CODE;

public class Result<T> {

    private Integer code; //状态码

    private String msg; //提示信息

    private T data; //数据

    private long timestamp;//接口请求时间

    public Result() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(T data) {
        Result<T> r = new Result<>();
        r.setCode(RETURN_CODE.RC200.getCode());
        r.setMsg(RETURN_CODE.RC200.getMsg());
        r.setData(data);
        return r;
    }

    public static <T> Result<T> success() {
        Result<T> r = new Result<>();
        r.setCode(RETURN_CODE.RC200.getCode());
        r.setMsg(RETURN_CODE.RC200.getMsg());
        return r;
    }


    public static <T> Result<T> error(int code, String msg) {
        Result<T> r = new Result<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }

    public static <T> Result<T> error(String msg) {
        Result<T> r = new Result<>();
        r.setCode(RETURN_CODE.RC201.getCode());
        r.setMsg(msg);
        r.setData(null);
        return r;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
}
